package com.training.java.core.collections.car.pre15;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * Created multiple objects to adding them to List. Car1,Car2,Car3 are immutable
 * objects. List accepts duplicate values.
 * 
 * @author Satya
 * 
 */
public class CarListDemo {

	public static void main(String[] args) {
		// Created multiple car objects.
		Car car1 = new Car("1234", "Ford", "Focus");
		Car car2 = new Car("2345", "Toyota", "Camry");
		Car car3 = new Car("3456", "BMW", "X5");
		Car car4 = new Car();// mutable object.
		Car car5 = new Car("3456", "BMW", "X5");// duplicate object

		// Creating the container collections

		List cars = new ArrayList();

		// Add the objects to the container
		cars.add(car1);
		cars.add(car2);
		cars.add(car3);
		cars.add(car4);
		cars.add(car5);// duplicate of car3
		cars.add(null);

		// iterator
		Iterator ite = cars.iterator();
		while (ite.hasNext()) {
			Car aCar = (Car) ite.next();// TypeCasting...

			// printing the car details

			System.out.println("Vin Number = " + aCar.getVinNumber());
			System.out.println("Make = " + aCar.getMake());
			System.out.println("Model = " + aCar.getModel());
			System.out.println("*************************");
		}

	}

}
